<div id="top_nav">
    <span id="here_area">当前位置：系统&nbsp;>&nbsp;毕业论文课题审查&nbsp;>&nbsp;待审查课题</span>
</div>
<div id="content">
    <div id="selector">
        <div>
            <div class="layui-form-item">
                <label class="layui-form-label">教师姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="teachername" placeholder="请输入教师姓名"
                           autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">教师工号</label>
                <div class="layui-input-inline">
                    <input type="text" name="teacherid" placeholder="请输入教师工号"
                           autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">课题名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="subname" placeholder="请输入课题名称"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <button id="select" class="layui-btn layui-btn-normal" >查询</button>
                </div>
            </div>
        </div>

        <script>
            $("#select").click(function() {
                var techearname = $("input[name=teachername]").val();
                var teacherid = $("input[name=teacherid]").val();
                var subname = $("input[name=subname]").val();
                $.ajax({
                    url:"Admin/query1",
                    type:"post",
                    data: {
                        "teachername":techearname,
                        "teacherid":teacherid,
                        "subname":subname
                    },
                    success:function(data){
                        console.log(data)
                        $("#tablecontent").html("");
                        for (var index in data) {
                            $("#tablecontent").append("<tr>\n" +
                                "                <td align=\"center\">" + data[index]["teh_name"] + "</td>\n" +
                                "                <td align=\"center\">" + data[index]["sbj_name"] + "</td>\n" +
                                "                <td align=\"center\">\n" +
                                "                    <button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"subDetail('" + data[index]["sbj_id"] + "')\">查看</button>\n" +
                                "                </td>\n" +
                                "                <td align=\"center\" id='" + data[index]["sbj_id"] + "'>\n" +
                                "                    <button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"checkSub('" + data[index]["sbj_id"] + "',1)\">通过</button>\n" +
                                "                    <button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"checkSub('" + data[index]["sbj_id"] + "',0)\">拒绝</button>\n" +
                                "                </td>\n" +
                                "</tr>");
                        }
                    }
                });
            });
        </script>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin: 20px;width: 90%">
        <legend> 待审查课题</legend>
    </fieldset>
    <div id="table">
        <table class="layui-table" style="margin-left: 15px;margin-right: 40px;margin-top:20px;width: 80%">
            <colgroup>
                <col width="150">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>教师名称</th>
                <th>课题名称</th>
                <th>详细信息</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="tablecontent">

            </tbody>
        </table>
    </div>

    <div id="pageselector" style="margin: 15px"></div>
    <script>
        function getCurPageData(curPage, limit) {
            $.ajax({
                url: "Admin/getchecksub1",
                type: "POST",
                data: {
                    "curPage": curPage,
                    "limit": limit
                },
                success: function (data) {
                    $("#tablecontent").html("");
                    for (var index in data) {
                        $("#tablecontent").append("<tr>\n" +
                            "                <td align=\"center\">" + data[index]["teh_name"] + "</td>\n" +
                            "                <td align=\"center\">" + data[index]["sbj_name"] + "</td>\n" +
                            "                <td align=\"center\">\n" +
                            "                    <button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"subDetail('" + data[index]["sbj_id"] + "')\">查看</button>\n" +
                            "                </td>\n" +
                            "                <td align=\"center\" id='" + data[index]["sbj_id"] + "'>\n" +
                            "                    <button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"checkSub('" + data[index]["sbj_id"] + "',1)\">通过</button>\n" +
                            "                    <button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"checkSub('" + data[index]["sbj_id"] + "',0)\">拒绝</button>\n" +
                            "                </td>\n" +
                            "</tr>");
                    }
                }
            });
        }

        layui.use(['laypage', 'jquery'], function () {

            var laypage = layui.laypage;

            laypage.render({
                elem: 'pageselector'
                , count: ${amout} //数据总数
                , theme: '#1E9FFF'
                , limit: 5
                , jump: function (obj) {
                    getCurPageData(obj.curr, obj.limit);
                }
            });
        });
    </script>
</div>
<script>
    function subDetail(subId) {
        $.ajax({
            url: "Admin/getsubdetail",
            type: "POST",
            data: {
                "sub_id": subId,
            },
            success: function (data) {
                console.log(data);
                layer.open({
                    type: 1
                    , title: '详细信息'
                    , area: ['500px', '600px']
                    , shade: 0
                    , content: "" +
                        "<div style='margin: 15px'>" +
                        "<div class=\"layui-form-item\">\n" +
                        "    <label class=\"layui-form-label\">教师工号</label>\n" +
                        "    <div class=\"layui-input-inline\">\n" +
                        "      <input type=\"text\" value='" + data["teh_id"] + "' name=\"title\" lay-verify=\"title\" autocomplete=\"off\" class=\"layui-input\" readonly=\"true\">\n" +
                        "    </div>\n" +
                        "  </div>" +
                        "<div class=\"layui-form-item\">\n" +
                        "    <label class=\"layui-form-label\">教师名称</label>\n" +
                        "    <div class=\"layui-input-inline\">\n" +
                        "      <input type=\"text\" value='" + data["teh_name"] + "' name=\"title\" lay-verify=\"title\" autocomplete=\"off\" class=\"layui-input\" readonly=\"true\">\n" +
                        "    </div>\n" +
                        "  </div>" +
                        "<div class=\"layui-form-item\">\n" +
                        "    <label class=\"layui-form-label\">课题名称</label>\n" +
                        "    <div class=\"layui-input-inline\">\n" +
                        "      <input type=\"text\" value='" + data["sbj_name"] + "' name=\"title\" lay-verify=\"title\" autocomplete=\"off\" class=\"layui-input\" readonly=\"true\">\n" +
                        "    </div>\n" +
                        "  </div>" +
                        "<div class=\"layui-form-item layui-form-text\">\n" +
                        "    <label class=\"layui-form-label\">课题描述</label>\n" +
                        "    <div class=\"layui-input-block\">\n" +
                        "      <textarea class=\"layui-textarea\" readonly=\"true\">" + data["sbj_describe"] + "</textarea>\n" +
                        "    </div>\n" +
                        "  </div>" +
                        "<div class=\"layui-form-item layui-form-text\">\n" +
                        "    <label class=\"layui-form-label\">课题书</label>\n" +
                        "    <div class=\"layui-input-block\">\n" +
                        "      <button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"downloadWord('" + data['sbj_id'] + "','" + data['teh_id'] + "')\">下载</button>\n" +
                        "    </div>\n" +
                        "  </div>" +
                        "</div>"
                    , btn: ['确定']
                    , yes: function () {
                        layer.closeAll();
                    }
                });
            }
        })
    }

    function checkSub(subid, ispass) {
        $.ajax({
            url: "Admin/approve",
            type: "POST",
            data: {
                "sbj_id": subid,
                "is_pass": ispass
            },
            success: function (data) {
                if (ispass == 0) {
                    $("#" + subid).html("已拒绝")
                }
                if (ispass == 1) {
                    $("#" + subid).html("已通过")
                }
            }
        });
    }

    function downloadWord(subId, tecId) {
        window.location.href = "Admin/download?sub_id=" + subId + "&teacherid=" + tecId;
    }
</script>


